package com.wlyuan.open.scanner.constant;

import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author lijing
 * @Description 表类型 枚举
 */
@Getter
public enum TableEnum {

    DEFAULT("", "", ""),
    //租户-增量同步时用
    TENANT("租户", "Company_ID", "TMS_Company"),
    //用户
    USER("用户", "User_ID", "TMS_User"),
    //司机
    DRIVER("司机", "Driver_ID", "TMS_MDriver"),
    //车辆
    VEHICLE("车辆", "Car_ID", "TMS_MCar"),
    //客户
    CUSTOMER("客户", "Customer_ID", "TMS_MCustomer"),
    //线下承运方
    CARRIER_OFFLINE("线下承运方", "Symbol_ID", "TMS_MSymbol"),
    //承运方
    CARRIER_ONLINE("线上承运方", "Supplier_ID", "TMS_MSupplier"),
    //物品
    GOODS("物品", "Goods_ID", "TMS_MGoods"),
    //收货方
    CONSIGNEE("收货方", "EndUser_ID", "TMS_MEndUser"),
    //合同
    CONTRACT("合同", "Index_ID", "TMS_ContractIndex"),
    //订单
    ORDER("订单", "Index_ID", "TMS_OrderIndex"),
    //合约/报价
    PRICE("合约", "Index_ID", "Price_DocIndex"),
    //合约/报价
    PRICE_DETAIL("合约明细", "Index_ID", "Price_DocDetails"),
    //对账单
    BILL("对账单", "Index_ID", "Balance_BillIndex"),
    //地址
    ADDR("地址", "Addr_CustomerID", "TMS_MAddr"),
    //附件
    ATTACH("附件", "Attach_OwnerID", "TMS_Attach"),
    //多段轨迹
    ADDITION("轨迹", "Transport_OrderId", "TMS_OrderAdditionTransport"),
    //收付款
    PAY("收付款", "Check_DetailID", "Balance_CheckDetails"),
    //报价
    ORDER_CACHE("报价", "Caches_OrderID", "TMS_OrderIndexCaches"),
    ORDER_EXTENSION("扩展信息", "Extension_id", "TMS_Extension"),
    ;

    /**
     * 值
     */
    private String val;

    private String autoIdColumn;

    /**
     * 名称
     */
    private String name;

    TableEnum(String name, String autoIdColumn, String val) {
        this.val = val;
        this.autoIdColumn = autoIdColumn;
        this.name = name;
    }

    private static final Map<String, TableEnum> MAP = Arrays.asList(TableEnum.values()).stream().collect(Collectors.toMap(TableEnum::getVal, Function.identity()));

    public static TableEnum fromName(String tableName) {
        return Optional.ofNullable(MAP.get(tableName)).orElse(null);
    }

    public static boolean isAddr(String val) {
        return ADDR.getVal().equals(val);
    }
}
